package com.example.qxfw.nyqx.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.qxfw.common.entity.ny.CropGrowdateIndexlib;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
@DS("service")
public interface CropGrowdateIndexlibMapper extends BaseMapper<CropGrowdateIndexlib> {

    @Select("select distinct cropname " +
            "from crop_growdate_indexlib")
    List<String> selectCropName();

    @Select("select cropName " +
            "from crop_growdate_indexlib " +
            "where indexid = #{indexId} ")
    List<String> selectCropName1(String indexId);

    @Select("select distinct type " +
            "from crop_growdate_indexlib " +
            "where cropname='${cropName}' ")
    List<String> selectType(String cropName);

    @Select("select distinct type " +
            "from crop_growdate_indexlib " +
            "where cropname like '%晚稻%' ")
    List<String> selectType1();

    @Select("select growdatename " +
            "from crop_growdate_indexlib " +
            "where cropname='${cropName}' " +
            "order by growdatestarttime")
    List<String> selectGrowDateName(String cropName);

    @Select("select distinct growdatename, growdatestarttime " +
            "from crop_growdate_indexlib " +
            "where cropname='${cropName}' " +
            "order by growdatestarttime")
    List<CropGrowdateIndexlib> selectList(String cropName);

    @Select("select cropname,type, growdatename " +
            "from crop_growdate_indexlib " +
            "where (growdatestarttime<='${time1}' and growdateendtime>='${time1}')or (growdatestarttime<='${time2}' and growdateendtime>='${time2}')or(growdatestarttime>='${time1}' and growdateendtime<='${time2}') or (growdatestarttime<='${time1}' and growdateendtime>='${time2}') ")
    List<CropGrowdateIndexlib> selectList1(String time1,String time2);

    @Select("select indexid,cropname,type, growdatename " +
            "from crop_growdate_indexlib " +
            "where (growdatestarttime<='${time1}' and growdateendtime>='${time1}')or (growdatestarttime<='${time2}' and growdateendtime>='${time2}')or(growdatestarttime>='${time1}' and growdateendtime<='${time2}') or (growdatestarttime<='${time1}' and growdateendtime>='${time2}') ")
    List<CropGrowdateIndexlib> selectList2(String time1,String time2);

    @Select("select indexid, cropname, growdatename, type, defendmeasure " +
            "from crop_growdate_indexlib " +
            "where ('${date1}' between growdatestarttime and growdateendtime) or ('${date2}' between growdatestarttime and growdateendtime) or ('${date3}' between growdatestarttime and growdateendtime) ")
    List<CropGrowdateIndexlib> selectList3(String date1,String date2,String date3);

    @Select("select indexid, cropname, growdatename, type, defendmeasure " +
            "from crop_growdate_indexlib " +
            "where '${month}' BETWEEN to_char(growdatestarttime,'MM-dd') AND to_char(growdateendtime,'MM-dd') ")
    List<CropGrowdateIndexlib> selectList4(String month);

    @Select("select indexid, cropname, growdatename, type, defendmeasure " +
            "from crop_growdate_indexlib " +
            "where '${month}' BETWEEN to_char(growdatestarttime,'MM-dd') AND to_char(growdateendtime,'MM-dd') and cropname = '${cropName}' ")
    List<CropGrowdateIndexlib> selectList5(String month,String cropName);

    @Select("select indexid, cropname, growdatename, type, defendmeasure " +
            "from crop_growdate_indexlib " +
            "where '${month}' BETWEEN to_char(growdatestarttime,'MM-dd') AND to_char(growdateendtime,'MM-dd') and cropname = '${cropName}' AND  type LIKE '${type}' ")
    List<CropGrowdateIndexlib> selectList6(String month,String cropName,String type);

    @Select("select joinstation " +
            "from crop_growdate_indexlib " +
            "where indexid='${indexId}' ")
    List<String> getJoinStation(String indexId);

    @Update("update crop_growdate_indexlib set " +
            "growdatestarttime = to_char(${cropGrowdateIndexlib.growdatestarttime},'yyyy-MM-dd HH24:MI:SS' and growdateendtime = to_char(${cropGrowdateIndexlib.growdateendtime},'yyyy-MM-dd HH24:MI:SS')")
    Integer update(CropGrowdateIndexlib cropGrowdateIndexlib);

}
